import PureCompanyManageList from '../components/company-list';
import * as ReactRedux from 'react-redux';
import { getFetchStatus } from 'actions/util';
import * as CompanyAction from 'actions/company';

const mapStateToProps = state => {
  return {
    fetchingCompanies: getFetchStatus(state, CompanyAction.search),
    companies: state.searchCompanyList
  };
};

const mapDispatchToProps = dispatch => {
  return {
    onCompanySearch(query) {
      dispatch(CompanyAction.search(query));
    },
    onCompanyInsert(company, query) {
      return dispatch(CompanyAction.create(company))
        .then(()=>dispatch(CompanyAction.search(query)))
    },
    onCompanyUpdate(company, query) {
      return dispatch(CompanyAction.update(company))
        .then(()=>dispatch(CompanyAction.search(query)))
    }
  };
};

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(PureCompanyManageList);
